program HelloWorld;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  Windows,
  DIrr in '..\..\DSource\DIrr.pas',
  DIrr.IO in '..\..\DSource\DIrr.IO.pas',
  DIrr.Irr in '..\..\DSource\DIrr.Irr.pas',
  DIrr.Mem in '..\..\DSource\DIrr.Mem.pas',
  DIrr.GUI in '..\..\DSource\DIrr.GUI.pas',
  DIrr.Base in '..\..\DSource\DIrr.Base.pas',
  DIrr.Core in '..\..\DSource\DIrr.Core.pas',
  DIrr.Math in '..\..\DSource\DIrr.Math.pas',
  DIrr.Rect in '..\..\DSource\DIrr.Rect.pas',
  DIrr.Color in '..\..\DSource\DIrr.Color.pas',
  DIrr.Scene in '..\..\DSource\DIrr.Scene.pas',
  DIrr.Types in '..\..\DSource\DIrr.Types.pas',
  DIrr.Video in '..\..\DSource\DIrr.Video.pas',
  DIrr.Config in '..\..\DSource\DIrr.Config.pas',
  DIrr.Line2D in '..\..\DSource\DIrr.Line2D.pas',
  DIrr.Line3D in '..\..\DSource\DIrr.Line3D.pas',
  DIrr.Matrix4 in '..\..\DSource\DIrr.Matrix4.pas',
  DIrr.Plane3D in '..\..\DSource\DIrr.Plane3D.pas',
  DIrr.Aabbox3D in '..\..\DSource\DIrr.Aabbox3D.pas',
  DIrr.Vector2D in '..\..\DSource\DIrr.Vector2D.pas',
  DIrr.Vector3D in '..\..\DSource\DIrr.Vector3D.pas',
  DIrr.WrapType in '..\..\DSource\DIrr.WrapType.pas',
  DIrr.Dimension2d in '..\..\DSource\DIrr.Dimension2d.pas',
  DIrr.Consts in '..\..\DSource\DIrr.Consts.pas',
  DIrr.Quake3 in '..\..\DSource\DIrr.Quake3.pas',
  DIrr.Structs in '..\..\DSource\DIrr.Structs.pas',
  DIrr.Buffer in '..\..\DSource\DIrr.Buffer.pas',
  DIrr.Collections in '..\..\DSource\DIrr.Collections.pas',
  DIrr.GPU in '..\..\DSource\DIrr.GPU.pas',
  DIrr.Material in '..\..\DSource\DIrr.Material.pas',
  DIrr.Particle in '..\..\DSource\DIrr.Particle.pas',
  DIrr.Quaternion in '..\..\DSource\DIrr.Quaternion.pas',
  DIrr.RenderServices in '..\..\DSource\DIrr.RenderServices.pas',
  DIrr.Texture in '..\..\DSource\DIrr.Texture.pas',
  DIrr.Triangle3D in '..\..\DSource\DIrr.Triangle3D.pas',
  DIrr.Event in '..\..\DSource\DIrr.Event.pas';

var
  device: TIrrlichtDevice;

  driver: TVideoDriver;
  smgr: TSceneManager;
  guienv: TGUIEnvironment;
  node: TAnimatedMeshSceneNode;
  mesh: TAnimatedMesh;
begin
  try
    { TODO -oUser -cConsole Main : Insert code here }

    ReportMemoryLeaksOnShutdown := True;

    device := CreateDevice(EDT_SOFTWARE, [640, 480], 16);

    if not Assigned(device) then
    begin
      ExitCode := 1;
      Exit;
    end;

    device.SetWindowCaption('Hello World! - Irrlicht Engine Demo');

    driver := device.GetVideoDriver;
    smgr := device.GetSceneManager;
    guienv := device.GetGUIEnvironment;

    guienv.AddStaticText('Hello World! This is the Irrlicht Software renderer!',
      [10, 10, 260, 22], True);

    mesh := smgr.GetMesh('..\..\media\sydney.md2');
    if not Assigned(mesh) then
    begin
      ExitCode := 1;
      Exit;
    end;

    node := smgr.AddAnimatedMeshSceneNode(mesh);

    if Assigned(node) then
    begin
      node.SetMaterialFlag(EMF_LIGHTING, False);
      node.SetMD2Animation(EMAT_STAND);
      node.SetMaterialTexture(0, driver.GetTexture('..\..\media\sydney.bmp'));
    end;

    smgr.AddCameraSceneNode(nil, Vector3DF(100, 100, -100), Vector3DF(0, 5, 0));

    while device.Run do
    begin
      driver.BeginScene(True, True, [255, 100, 101, 140]);

      smgr.DrawAll;
      guienv.DrawAll;

      driver.EndScene;
    end;

    device.Drop;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
